<?php
/**
 * Created by PhpStorm.
 * User: Wang YuLong
 * Date: 2018/11/13
 * Time: 19:22
 */
namespace app\index\controller;

use think\Controller;

class Backup extends Comm
{
    //数据库备份
    public function bak(){
        $type=input("tp");
        $name=input("name");
        $sql=new \org\Baksql(\think\Config::get("database"));
        switch ($type)
        {
            case "backup": //备份
                $info = $sql->backup();
                zsgc('添加了数据库备份 ');
                $this->success("$info",'index/backup/bak');
                break;
            case "dowonload": //下载
                $info = $sql->downloadFile($name);
                zsgc('下载了名为'.$name.'数据库备份');
                $this->success("$info",'index/backup/bak');
                break;
            case "restore": //还原
                $info = $sql->restore($name);
                zsgc('还原了名为'.$name.'数据库备份');
                $this->success("$info",'index/backup/bak');
                break;
            case "del": //删除
                $info = $sql->delfilename($name);
                zsgc('删除了了名为'.$name.'数据库备份');
                $this->success("$info",'index/backup/bak');
                break;
            default: //获取备份文件列表
                return $this->fetch("bak",["list"=>$sql->get_filelist()]);
        }
    }
}